import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
//+++++++++
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // ++++++++
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    // 带选项写法：http://localhost:5173/api/bar -> http://jsonplaceholder.typicode.com/bar
    proxy: {
      '/api': {  // 当访问的地址中包含/api字段时候, 就将该请求的域名服务器地址代理到target服务器地址上
        target: 'http://47.94.148.165:3001',
        changeOrigin: true,  //是否跨域
        rewrite: (path) => path.replace(/^\/api/, ''), // 将api字段替换为''
      },
    }
  }
})
